<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background: darkcyan;
            color: #dfdfdf;
        }
    </style>
</head>

<body>
    <div id="app">
        <h2>{{title}}</h2>
        <parent id="2116" :msg="msg" :title="title"></parent>
    </div>
    <template id="parent">
        <div>
            <h2>{{title}} --parent</h2>
            <!-- <h2>{{count}}--parent</h2> -->
            <button @click="count++"> 改变count</button>
            <button @click="changenum">改变num</button>
            <button @click="show=!show">{{show?'隐藏':'显示'}}</button>
            <hr>
            <childone :mycount="count" :show="show" ref="childone"></childone>
        </div>
    </template>
    <template id="childone">
        <div>
            <h2>{{ mycount}} --child</h2>
            <h2>{{num}}</h2>
            <div class="box" v-show="show"></div>
        </div>
    </template>
</body>
<script>
    Vue.component('parent', {
        template: "#parent",
        data() {
            return {
                count: 520,
                show: true
            }
        },
        props: {
            title: String,
        },
        methods: {
            changenum() {
                this.$refs.childone.num++;
            }
        }
    })
    Vue.component('childone', {
        template: "#childone",
        props: {
            mycount: Number,
            show: Boolean
        },
        data() {
            return {
                num: 2022
            }
        }
    })
    const vm = new Vue({
        // el:"#app",
        components: {
        },
        data: {
            title: "Vue 组件初步 (组件通信 - props ) ",
            msg: "小型、独立和通常可复用的组件构建大型应用"
        },
        mounted() {
            document.getElementsByTagName('title')[0].innerHTML = this.title
        }
    }).$mount("#app")
</script>

</html>